var windowName = "shopIndex";
var Page,goodsList;
apiready = function(){
    onWindowShow(function () {
        console.log(windowName + " show")
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    goodsList= new List();
    Page = createVM("#Page",{
        curTab:0
        , loading: true
        ,id:0
        ,shop:{
            "id": 3,
            "user": "/api_/users/1",
            "name": "用户_15265461237的店铺",
            "logo": "/qz/4226tbrGZt3XNehQaSAzkep2jAZfsZG8p3ekCzCWEnYdMFwkCwZtYKbmrX8a8Afa.jpg",
            "head": "/qz/pfZyWzfDM4t7siKdtEGh5zpSz65ARsiRttamJ4c7an6hABKiEDcBfFzwrnhijwSd.jpg",
            "openStart": 0,
            "openEnd": 0,
            "province": null,
            "city": "东营市",
            "area": null,
            "address": "东营市众成明月华庭山东省东营市东营区G220(南二路)",
            "intro": "欢迎光临我的店铺！",
            "pics": [
                "/qz/pfZyWzfDM4t7siKdtEGh5zpSz65ARsiRttamJ4c7an6hABKiEDcBfFzwrnhijwSd.jpg",
                "/qz/XisCDtt3ifZKfsxEXCreTids7k5eStRHAD8B3fkpFa8ADzznR6Gpm685M2wXxYEw.png",
                "/qz/2w48jkS7fMRGWbeibc4YjAT2SCZhZ8QKjfRZDfKPEXAAzw4TzPMfZ2JDFnKH63a4.jpg",
                "/qz/XwD8wDhx3rKpPCaRaTAxCPJkWS6jF28TWNEBGQ464CeyrrYxGXdPjeRC45fhAzJa.png"
            ],
            "lat": 37.411411,
            "lon": 118.657893,
            "phone": "15265461237",
            "isAuth": 1,
            "auths": [
                "/api_/shop_auths/1",
                "/api_/shop_auths/2",
                "/api_/shop_auths/3"
            ],
            "tags": [

            ],
            "tagAppeals": [

            ],
            "products": [
                "/api_/products/1",
                "/api_/products/2"
            ],
            "openStr": "全天营业",
            "statistic": "/api_/shop_statistics/1"
        }
        ,comments:[]
        ,goods:[]
        ,cert:[]
    },{
        //页面方法
        "init":function () {
            var data = getData4Page()
            this.id = data.id
            getData()

            var shop = getLocData("shopIndexShop")
            this.shop = shop
            goodsList.setUrl("/app/shop/products").setData({id:Page.id}).setCbFunc(function (res) {
                clearLoading();
                Page.goods = res
            }).getList()

            apiGet("/app/shop/get/cert",{id:this.id},function (res,code) {
                Page.cert = res.data
                logJson(res.data)
            })
        }
        , tab: function (index) {
            this.curTab = index

        }
        ,baiduditu:baiduditu
    })
    Page.init();
    onPullUpLoadMore(function () {

        goodsList.getList()
    })
}

function getData() {
    apiGet("/api/shops/" + Page.id, {}, function (res , code) {
        setLocData("shopIndexShop",res.data);
        clearLoading();
        logJson(res.data)
        Page.shop = res.data
    });
    // apiGet("/app/shop/products",{id:Page.id},function (res,code) {
    //     logJson(res,"/app/shop/products")
    //     Page.goods = res.data
    // })
    apiGet("/app/get/comments",{what:Page.id},function (res,code) {
        logJson(res,"/app/get/comments")
        Page.comments = res.data
    })
}